package com.jbit.redisserver.utils;

import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

public class RedisUtils {
    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    public void set(String key,Object value){
        redisTemplate.opsForValue().set(key,value);
    }

    public void set(String key,Object value,Integer expire){
        redisTemplate.opsForValue().set(key,value,expire, TimeUnit.SECONDS);
    }

    public Object get(String key){
        return redisTemplate.opsForValue().get(key);
    }

    public boolean del(String key){
        return redisTemplate.delete(key);
    }

    public boolean exists(String key){
        return redisTemplate.hasKey(key);
    }
}
